package gcosc.fun.hly.fastsso.controller;


import gcosc.fun.hly.fastsso.domain.Bo.PageQuery;
import gcosc.fun.hly.fastsso.domain.SsoApplication;
import gcosc.fun.hly.fastsso.result.Result;
import gcosc.fun.hly.fastsso.result.TableDataInfo;
import gcosc.fun.hly.fastsso.service.ISsoApplicationService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;

/**
 * 应用程序
 *
 * @author hly
 * @date 2023-12-30
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/sso/application")
public class SsoApplicationController {

    private final ISsoApplicationService iSsoApplicationService;

    /**
     * 查询应用程序列表
     */
    @GetMapping("/list")
    public TableDataInfo<SsoApplication> list(SsoApplication bo, PageQuery pageQuery) {
        return iSsoApplicationService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出应用程序列表
     */
//    @SaCheckPermission("system:application:export")
//    @Log(title = "应用程序", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(SsoApplication bo, HttpServletResponse response) {
//        List<SsoApplicationVo> list = iSsoApplicationService.queryList(bo);
//        ExcelUtil.exportExcel(list, "应用程序", SsoApplicationVo.class, response);
//    }

    /**
     * 获取应用程序详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public Result<SsoApplication> getInfo(@PathVariable Long id) {
        return Result.ok(iSsoApplicationService.queryById(id));
    }

    /**
     * 新增应用程序
     */
    @PostMapping()
    public Result add(@RequestBody SsoApplication bo) {
        return Result.ok(iSsoApplicationService.insertByBo(bo));
    }

    /**
     * 修改应用程序
     */
    @PutMapping()
    public Result<Void> edit(@RequestBody SsoApplication bo) {
        return Result.ok(iSsoApplicationService.updateByBo(bo));
    }

    /**
     * 删除应用程序
     *
     * @param ids 主键串
     */
    @DeleteMapping("/{ids}")
    public Result<Void> remove(@PathVariable Long[] ids) {
        return Result.ok(iSsoApplicationService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
